﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.XPath;
using System.Collections;

namespace FTI.SP.LADM.EnhancedContentQueryWebPart.Exslt
{
    internal class ExsltNodeList
    {
        // Fields
        internal ArrayList innerList;

        // Methods
        public ExsltNodeList()
        {
            this.innerList = new ArrayList();
        }

        public ExsltNodeList(XPathNodeIterator iterator)
            : this(iterator, false)
        {
        }

        public ExsltNodeList(XPathNodeIterator iterator, bool removeDuplicates)
        {
            this.innerList = new ArrayList();
            XPathNodeIterator iterator2 = iterator.Clone();
            while (iterator2.MoveNext())
            {
                if (!removeDuplicates || !this.Contains(iterator2.Current))
                {
                    this.Add(iterator2.Current.Clone());
                }
            }
        }

        public int Add(XPathNavigator nav)
        {
            return this.innerList.Add(nav);
        }

        public void Clear()
        {
            this.innerList.Clear();
        }

        public bool Contains(XPathNavigator value)
        {
            foreach (XPathNavigator navigator in this.innerList)
            {
                if (navigator.IsSamePosition(value))
                {
                    return true;
                }
            }
            return false;
        }

        public bool ContainsValue(string value)
        {
            foreach (XPathNavigator navigator in this.innerList)
            {
                if (navigator.Value.Equals(value))
                {
                    return true;
                }
            }
            return false;
        }

        public IEnumerator GetEnumerator()
        {
            return this.innerList.GetEnumerator();
        }

        public int IndexOf(object value)
        {
            return this.innerList.IndexOf(value);
        }

        public void Insert(int index, XPathNavigator nav)
        {
            this.innerList.Insert(index, nav);
        }

        public void Remove(XPathNavigator nav)
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (nav.IsSamePosition((XPathNavigator)this.innerList[i]))
                {
                    this.innerList.RemoveAt(i);
                    return;
                }
            }
        }

        public void RemoveAt(int index)
        {
            this.innerList.RemoveAt(index);
        }

        // Properties
        public int Count
        {
            get
            {
                return this.innerList.Count;
            }
        }

        public XPathNavigator this[int index]
        {
            get
            {
                return (XPathNavigator)this.innerList[index];
            }
            set
            {
                this.innerList[index] = value;
            }
        }

    }
}
